home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
228_01
/
bdsmark.doc
< prev
next >
Wrap
Text File
|
1987-07-29
|
19KB
|
346 lines
BDSMARK.C
David D. Clark
507 N. Division St.
Bristol, IN 46507
The Problem
BD Softwares' C compiler was one of the first C compilers
for micro computers and is still one of the best. A lot of
good public domain and commercial software (like my favorite
word processing program and another of my favorite C
compilers) has been written with it. It is a fast
development system and produces fast and compact code.
Unfortunatley, it is only available for CP/M systems. If
you have a computer running a different operating system or
CPU and you want to port some of the excellent software
written in BDS C, you have to resort to a different compiler
on the new machine. That is not the only problem however.
BDS C prior to version 1.6 is not a particularly portable
version of C because a number of the "standard" library
routines are not standard as used in "The C Programming
Language" (1) (hereafter referred to as "K&R") or C compilers
running on UNIX. (Some of these routines do not really
exist in the UNIX C standard library but are simulations of
UNIX system calls on a CP/M system.)
When I started working with a Zenith Z-150 running MS-DOS,
I was faced with the formidable task of porting a lot of my
favorite public domain and self-written programs, written in
BDS C, to the new system. Too, now that version 1.6 has
arrived, with its more standard i/o library, I have a lot of
code that needs translation to the new version as well.
The Nonstandard "Standard" Functions
After a bit of careful reading, I determined that there
were 9 functions in the old (pre version 1.6) BDS C standard
library that were not implemented as per K&R or, if K&R was
not clear about a particular function, the UNIX version 7 C
compiler. Some of the differences are trivial, others are
not. These functions, and the differences between the BDS
version and the standard version, are listed below:
creat The BDS C version requires only one
parameter, the file name, while the K&R
version requires two: the file name and a
protection mode. Admittedly, the protection
mode argument is useless in a CP/M
environment, but may be needed under a
different operating system. This function is
the same in the new version of the BDS
library.
exit According to K&R, exit will flush any open
buffered files before closing them. BDS C
does not flush the file buffer before closing
the file.
fgets Again, there is a difference in the number
and meaning of parameters accepted by the old
BDS C function and the K&R version. The old
BDS C function expects to be called with a
pointer to the string to fill and a pointer
to a BDS C specific file buffer associated
with the input device. The K&R version also
expects to be called with a pointer to the
string to be filled, but followed by the
maximum number of characters to fill the
string with and a pointer to a FILE variable
associated with the input device. This
version of this function included with
version 1.6 of BDS C is K&R compatible.
fopen In this case, the arguments and the value
returned by the functions are different. The
old BDS library function expects to be called
with a pointer to the name of the file and a
pointer to the buffer variable to be
associated with the open file. It returns an
integer representing the file descriptor of
the opened file or -1 if an error occurs
during the attempt to open the file. The K&R
version also expects a pointer to the name of
the file but expects a pointer to a character
representing the mode (read, write or append)
in which the file is to be opened. The
function returns a pointer to a FILE variable
to be associated with the open file or NULL
in case of an error. The new BDS C 1.6
function is compatible.
getc The new version of this function differs from
the old in that it now differentiates between
text and binary modes. In text mode, CP/M
line end sequences (a carriage return/line
feed pair) is translated to a single line
feed character.
getchar The new version of this function
distinguishes between text and binary modes
like getc.
putc The new version of this function also
differentiates between binary and text
modes.
puts The difference here is small but can greatly
affect screen displays that use the
function. The UNIX version of the function
always appends a new line character to the
end of the string it prints to the standard
output. The BDS function does not.
read In this case, one of the arguments in the BDS
version of the function represents the number
of 128 byte blocks to be read. This is
reasonable in a CP/M environment where the
smallest unit of disk I/O is 128 bytes. The
K&R version of the function expects the
corresponding argument to represent the
number of individual bytes to be read. The
functions return values representing
different things too. The BDS function
returns the number of blocks read while the
K&R version returns the number of bytes.
This function has not changed in the new
version of the BDS library.
tolower This function is somewhat ambiguously defined
in K&R. The UNIX version (a macro actually)
does the conversion regardless of whether of
not the argument was upper case to begin
with. The BDS function checks the argument
to determine if it is upper case before
performing the conversion. Most other
microcomputer versions of C do the same check
before conversion.
toupper The same problem occurs with this function as
with tolower. UNIX does not check the case
of the argument before converting while BDS C
does. This seems like a very innocuous
difference, but it is the one that most often
caused me trouble. Again